High stakes poker for sure. Sanctions haven't worked, appeasing the regime hasn't worked over the last 20 years either. N. Korea basically has Seoul as a hostage. Such a large city so close to the DMZ that just their conventional weapons have the ability to take potentially millions of lives.
China is the only country that can influence N. Korea. They know Un is a whack job. They don't want a power vacuum there since they already have issues with N. Koreans escaping to China. The only solution I see is somehow convincing China that they need to back a coup and take control of N. Korea. Un has purged a bunch of folks already, including relatives, who he thinks may not be 100% loyal.
I think Un sees having a nuke as a way to insure that no one attempts a regime change. He's probably correct in his assessment.